package com.cakeclient;


import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.cakeclient.Model.Client;

import java.util.List;

public class ListViewClientAccountsAdapter extends ArrayAdapter<Client> {
    int resource;
    Context context;
    List<Client> clients;

    boolean changeColor = true;
    int myGrey = Color.rgb(231, 227, 231);
    int myBlue = Color.rgb(198, 219, 222);

    public ListViewClientAccountsAdapter(Context context, int textViewResourceId, List<Client> clients) {
        super(context, textViewResourceId, clients);
        this.resource = textViewResourceId;
        this.context = context;
        this.clients = clients;
    }

    // On override ArrayAdapter
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Récuperer l'order courant
        LinearLayout objectView;

        // Récuperer le produit courant
        final Client client = getItem(position);


        // Inflate the catalog_detail_product
        if (convertView == null) {
            objectView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(inflater);
            vi.inflate(resource, objectView, true);
        } else {
            objectView = (LinearLayout) convertView;
        }

        // Récupérer les View
        TextView nameTextView = (TextView) objectView.findViewById(R.id.catalog_client_manageaccount_accountname_textview);

        // Pour les produits: une image du produit et le nom
        nameTextView.setText(client.getName() + " " + client.getFirstName());
        Client client1 = Client.getLocalClient(getContext());
        
        if (Client.getLocalClient(getContext()) != null && Client.getLocalClient(getContext()).getIdDB().equals(client.getIdDB())) {
                nameTextView.setTextColor(Color.rgb(200, 102, 102));

        }


        return (objectView);


    }
}
